package com.harmontronics.hanma.paas.paas.domain.app.repository.persistence;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.harmontronics.hanma.paas.paas.consts.EnvEnum;
import com.harmontronics.hanma.paas.paas.domain.app.entity.valueobject.Fields;
import com.harmontronics.hanma.paas.paas.domain.app.repository.mapper.HttpServiceSettingMapper;
import com.harmontronics.hanma.paas.paas.domain.app.repository.po.HttpServiceSettingPO;
import org.springframework.stereotype.Repository;


@Repository("httpServiceSettingRepository")
public class HttpServiceSettingRepository extends ServiceImpl<HttpServiceSettingMapper, HttpServiceSettingPO> {

    public IPage<HttpServiceSettingPO> selectPage(QueryWrapper<HttpServiceSettingPO> queryWrapper, Page<HttpServiceSettingPO> page) {
        return baseMapper.selectPage(page, queryWrapper);
    }

    public List<HttpServiceSettingPO> findByServiceIdIn(List<Long> idList) {
        QueryWrapper<HttpServiceSettingPO> queryWrapper=new QueryWrapper<>();
        queryWrapper.in(Fields.HTTP_SERVICE_ID,idList);
        return baseMapper.selectList(queryWrapper);
    }

    public List<HttpServiceSettingPO> findByServiceId(Long serviceId) {
        QueryWrapper<HttpServiceSettingPO> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq(Fields.HTTP_SERVICE_ID,serviceId);
        return baseMapper.selectList(queryWrapper);
    }

    public HttpServiceSettingPO findByServiceIdAndEnv(Long serviceId, EnvEnum envEnum) {
        QueryWrapper<HttpServiceSettingPO> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq(Fields.HTTP_SERVICE_ID,serviceId);
        queryWrapper.eq(Fields.ENV_DB,envEnum);
        return baseMapper.selectOne(queryWrapper);
    }

    public void deleteByServiceId(Long serviceId) {
        QueryWrapper<HttpServiceSettingPO> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq(Fields.HTTP_SERVICE_ID,serviceId);
        baseMapper.delete(queryWrapper);
    }
}